<?php


namespace App\Http\Controllers\Api;
use App\Models\Company;
use Dingo\Api\Http\Request;

class CompanyController extends BaseController
{
    /**
     * 列表
     * @param Request $request
     * @return mixed
     */
    public function index(Request $request) {
        $id = $request->input('company_id');
        $limit = $request->get('per_page',20);

        $list = Company::withCertain('type', ['value'])->when($id, function ($q) use($id) {
           $q->where('id', $id);
        })->orderBy('sort', 'desc')->orderBy("updated_at", "desc")
            ->paginate($limit);
        return $this->paginate($list);
    }

    /**
     * 详情
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    public function info(Request $request) {
        $this->validate($request, [
            'id' => 'required|exists:company'
        ]);
        $id = \request("id");
        $info = Company::withCertain('type', ['value'])->find($id);
        return $this->success($info);
    }



}

